package com.m7788.screen;

import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.widget.Toast;

import com.m7788.util.AppUtil;
import com.m7788.util.Constant;
import com.m7788.util.HttpService;
import com.m7788.view.UmengBaseActivity;

public class PaymentScreen extends UmengBaseActivity {
	String partnerUserId;
	String orderid;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		 partnerUserId = AppUtil.getRecord(this, Constant.PAY_USER_ID);
		
		 //partnerUserId = getIntent().getStringExtra("partnerUserId");		
		 orderid = getIntent().getStringExtra("orderId");
		String payResult = getIntent().getStringExtra("payResult");
		if (!TextUtils.isEmpty(orderid) && !TextUtils.isEmpty(payResult)) {
			int payResultCode = Integer.parseInt(payResult);
			String payResultStr = "";
			// 1：支付成功 2:支付失败 0： 交易取消
			switch (payResultCode) {
			case 0:
				payResultStr = "交易取消";
				break;
			case 1:
				payResultStr = "成功";
				AppUtil.saveRecord(PaymentScreen.this, Constant.PAY_LIST_URL_FLAG, "true");
				new UpdateQueryAsyncTask().execute();
				break;
			case 2:
				payResultStr = "失败";
				break;

			default:
				break;
			}
			Toast.makeText(this, "订单号：" + orderid + "，支付结果：" + payResultStr,
					Toast.LENGTH_SHORT).show();
		}
		finish();
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
	}
	
	private class UpdateQueryAsyncTask extends AsyncTask<Object, Object, Object> {
		@Override
		protected void onPostExecute(Object result) {
			
			if (result != null&&result.toString().length()>0) {
				
			} else {
			}
			super.onPostExecute(result);
		}

		@Override
		protected Object doInBackground(Object... params) {
			return HttpService.getInstance(PaymentScreen.this.getApplicationContext()).sendPayResult(partnerUserId, orderid);

		}
	}
}
